@tool
class_name ContextBehavior_Separation
extends ContextBehavior_Group

#region 属性
@export var decay_coefficient:float = 1.0
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
func init():
	super()
func calc_steering(behaviors_owner:Node,agent:SteeringBehaviorAgent,delta:float):
	super(behaviors_owner,agent,delta)
func get_target_pos(target:Node2D) -> Vector2:
	return super(target)
func get_interest() -> Vector2:
	var detect_component:DetectComponent = agent.entity.get_component(DetectComponent)
	if not detect_component:
		return Vector2.ZERO
	var detector_target:Detector_Target = detect_component.get_detector(GameEnum.DetectorType.Target)
	if not detector_target:
		return Vector2.ZERO
	var targets:Array = detector_target.get_targets(agent.get_pos(),radius,Callable(),-1)
	var interest = Vector2.ZERO
	for target in targets:
		var to_agent = agent.get_pos() - get_target_pos(target)
		var distance = to_agent.length()
		var strength = min(decay_coefficient / pow(distance,2),agent.linear_acceleration_max)
		interest += to_agent.normalized() * strength
	return interest.normalized()
#endregion
#region 公共方法
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _init() -> void:
	if Engine.is_editor_hint():
		resource_local_to_scene = true
	behavior_type = GameEnum.ContextBehaviorType.Separation
func draw() -> void:
	super.draw()
#endregion
